package dk.mirasola.systemtraining.bridgewidgets.client.ui.editor;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.safehtml.shared.SafeHtml;
import dk.mirasola.systemtraining.bridgewidgets.client.i18n.EditorTexts;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.ShapeElement;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.ShapeType;

import java.util.List;

public class ShapeTypeEditor extends ShapeElementsEditor implements LeafValueEditor<ShapeType> {
    private static final EditorTexts editorTexts = GWT.create(EditorTexts.class);

    @Override
    protected boolean isValid(List<ShapeElement> shapeElements) {
        return ShapeType.validate(shapeElements);
    }

    @Override
    protected SafeHtml getHelpInfo() {
        return editorTexts.shapeTypeHelpInfo();
    }

    @Override
    public void setValue(ShapeType value) {
        setValidatedShapeElement(value.getShapeElements());
    }

    @Override
    public ShapeType getValue() {
        return ShapeType.create(getValidatedShapeElements(), false);
    }
}
